#pragma once
#include "ClientSocket.h"
#include <map>

enum dataUpdateType
{
	noneUpdate = 0,
	otherDataChange			= 0x00000001,
	dataUpdateAreaInfo		= 0x00000002 ,
	dataUpdateAccountInfo	= 0x00000004 ,
};

typedef map<CString,INT64>  deskMap;

class frontManageData
{
public:
	frontManageData(CClientSocket* pSocket);
	CClientSocket* getSocket(){return m_pSocket;};
	void setAreaInfo(const vector<areaInfo>& vAreaInfo){
		m_vAreaInfo = vAreaInfo;
		m_UpdateDataType |= dataUpdateAreaInfo;
	};
	void getDeskName(CString& areaName,CString& deskName,int areaIndex,int deskIndex);
	void getDeskName(wchar_t* areaName,wchar_t* deskName,int nIndex);
	const vector<areaInfo>& getAreaInfo()const{return m_vAreaInfo;};
	void Lock(){EnterCriticalSection(&m_CriticalSection); }
	void UnLock(){LeaveCriticalSection(&m_CriticalSection);}
	unsigned int getUpdateType()const {return m_UpdateDataType;}
	void setUpdateType(unsigned int newType){Lock();m_UpdateDataType |= newType;UnLock(); }
	//bool setUpdate(bool update = true){m_isUpdateData = update;};
	void clearUpdateType(unsigned int clType);
	void clearUpdate(){Lock();m_UpdateDataType = noneUpdate;UnLock();}
	void SetNowUser(const userAccount& user){
		Lock();
		memcpy(&m_nowUser,&user,sizeof(userAccount));
		setUpdateType(dataUpdateAccountInfo);
		UnLock();
	}
	const userAccount& getNowUser()const{return m_nowUser;};
	void SetCompanyName(wchar_t* name,int length);
	const CString& getCompanyName(){return m_companyName;}

	void setPicturePath(const CString& path);
	void setPictureName(const CString& name);
	const CString& getPicturePath()const {return m_picturePath ;}
	void setEmployeeShort(const employeeShortInfo& shortInfo);
	const employeeShortInfo& getEmployeeShort()const {return m_employeeShort;};
	const bookSetData& getBookSetData()const {return m_bookData;};
	void setBookSetData(const bookSetData& bookData);
	void setBookData(const vector<bookManagerData>& pData){Lock();m_nowBookManagerData = pData;UnLock();};
	const vector<bookManagerData>& getBookData( )const{return m_nowBookManagerData;};
	void setFoodParam(const foodParam* foodName);
	const foodParam* getFoodParamById(const wchar_t* foodId);
	const foodParam* getFoodParamByAbbr(const wchar_t* abbr);
	const foodParam* getFoodParam(const wchar_t* abbr);
	bool getOrder(int nArea,int nDesktop,Order* pOrder);
	bool 	getOrder(int nIndex,Order* pOrder); 
	void			setOrder(int nArea,int nDesktop,const Order& pOrder);
	void			setOrder(const wchar_t* areaName,const wchar_t* deskName,const Order& pOrder);
	const orderOption& getOrderOption()const{return m_orderOption;}
	void setOrderOption(const orderOption& pOption){m_orderOption = pOption;}
	void setSerial(const wchar_t* areaName,const wchar_t* deskName,INT64 nSerial);
	void setAllDiscountPlan(const vector<discountPlan>& vPlan){m_vDiscountPlan = vPlan;};
	const vector<discountPlan>& getAllDiscountPlan()const {return m_vDiscountPlan;}
	void addCombine(int nSrcDesk,int nSrcArea,int nCombineDesk,int nCombineArea);
	void delCombine(int nCombineDesk,int nCombineArea);
	void delCombine(const wchar_t* areaName,const wchar_t* deskName);
	int getIndex(int nArea,int nDesk);
public:
	~frontManageData(void);
	CString m_Path;
private:
	vector<discountPlan> m_vDiscountPlan;
	map<CString,foodParam> m_foodParamMap;
	map<CString,CString> m_abbrToId;
	CClientSocket* m_pSocket;
	vector<areaInfo> m_vAreaInfo;
	CRITICAL_SECTION m_CriticalSection;
	unsigned int m_UpdateDataType;
	userAccount m_nowUser;
	CString m_companyName;
	CString m_picturePath;
	employeeShortInfo m_employeeShort;
	bookSetData			m_bookData;
	vector<bookManagerData>		m_nowBookManagerData;
	map<int,Order>				m_orderMap;
	orderOption					m_orderOption;
	map<CString,deskMap> m_areaMap;
	map<int,vector<int> >			m_CombinMap;


};
